import { delay } from 'redux-saga'
import { call, put, takeEvery } from 'redux-saga/effects'

import { INCREMENT, INCREMENT_ASYNC } from './action-types'

export function* incrementAsync(action) {
  yield call(delay, 1000)
  yield put({ type: INCREMENT, number: action.number })
}

export function* watchIncrementAsync() {
  yield takeEvery(INCREMENT_ASYNC, incrementAsync)
}

// single entry point to start all Sagas at once
export default function* rootSaga() {
  yield [
    watchIncrementAsync()
  ]
}
